<template>
  <div>
    <div class="register-wrapper">
      <div id="Login">
        <p class="title">登录</p>
        <el-form
          status-icon
          :model="login"
          ref="ruleForm2"
          label-width="0"
          class="demo-ruleForm"
        >
          <el-form-item prop="tel">
            <el-input v-model="login.user_name" placeholder="请输入手机号"></el-input>
          </el-form-item>
          <el-form-item prop="pass">
            <el-input v-model="login.password" type="password" auto-complete="off" placeholder="输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary"  @click="onLogin" style="width:100%;">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import * as loginAPI from '@/api/login/';

export default {
  name: "Login",
  data() {
    return {
      login: {
        user_name: '',
        password: '',
      },
    };
  },
  methods: {
    onLogin() {
      loginAPI.postUserLogin(this.login).then((res) =>{
        if (res.status > 0) {
          this.$notify.error({
            title: '登录失败',
            message: res.msg,
          });
        } else {

          this.$router.go(0);
          this.$router.push({ path: '/'})
          this.$notify({
            title: '登录成功',
            message: `已使用JWT登录`,
            type: 'success',
          });
        }
      }).catch((error) => {
        this.$notify.error({
          title: '网路错误，或者服务器宕机',
          message: error,
        });
      });
    },
  },
  components: {
  },
};
</script>

<style scoped>

#Login {
  max-width: 340px;
  margin: 60px auto;
  background: #fff;
  padding: 20px 40px;
  border-radius: 10px;
  position: relative;
  z-index: 9;
}
.title {
  font-size: 26px;
  line-height: 50px;
  font-weight: bold;
  margin: 10px;
  text-align: center;
}
.el-form-item {
  text-align: center;
}
.login {
  margin-top: 10px;
  font-size: 14px;
  line-height: 22px;
  color: #1ab2ff;
  cursor: pointer;
  text-align: left;
  text-indent: 8px;
  width: 160px;
}
.login:hover {
  color: #2c2fd6;
}
.code >>> .el-form-item__content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.code button {
  margin-left: 20px;
  width: 140px;
  text-align: center;
}
.el-button--primary:focus {
  background: #409EFF;
  border-color: #409EFF;
  color: #fff;
}
</style>
